<%-- 
    Document   : search_fun
    Created on : Oct 27, 2010, 4:51:06 PM
    Author     : M Bilal
--%>

<%@ page import="java.io.*,java.util.*,java.sql.*,java.net.*"%>
<%@ page import="wap.rockvilletech.portal.DBProc"%>
<%!
private String map_coolstuff_cat(String stuff){
    String strStuff="";
    try{
        if("Jokes".equalsIgnoreCase(stuff)){
           strStuff="1";
        }else if("Love Quotes".equalsIgnoreCase(stuff)){
            strStuff="2";
        }else{
            strStuff="";
        }
    }catch(Exception e){
        strStuff="";
    }
    return strStuff;
}

%>
<%
    DBProc dbproc=DBProc.getInstance();
    String strSearchText=(request.getParameter("txtsrh")!=null)?request.getParameter("txtsrh").toString():"";

    //Pagging
     int intBlockLength = 5, intRecordsToBeDisplayed = 0, intRecordsToBeFetched = 0, intCountTotal = 0, intPageID = 0, intLastPage = 0;
	String strPagingLinks = "", pid = "";
	boolean computePaging = false, isNext = true;
	pid = request.getParameter("pid") != null ? request.getParameter("pid").toString() : "0";
    Vector vFun = dbproc.getFunSearch(pid, strSearchText);
    if(vFun !=null){
    intCountTotal=(Integer)vFun.get(0);
    intRecordsToBeDisplayed=intRecordsToBeFetched=(Integer)(vFun.get(1));
	try {
		intLastPage = intCountTotal / intRecordsToBeDisplayed;
		intPageID = Integer.parseInt(pid.toString());
		if (intPageID > intLastPage) {
	        intPageID = intLastPage;
	    }
 if(intCountTotal == (int)(intRecordsToBeDisplayed*(intPageID+1))) intLastPage--;
    } catch(NumberFormatException ex){
    }

    if (vFun.size()-1 < intRecordsToBeFetched) {
		intRecordsToBeDisplayed -= (intRecordsToBeFetched - vFun.size());
		intRecordsToBeFetched = vFun.size();
		isNext = false;
	}

    computePaging = intCountTotal >intRecordsToBeDisplayed;
   if(computePaging){
       // Call the method which will generate Page links

		wap.rockvilletech.util.Paging.computePaging(request, "search.jsp?",
				intRecordsToBeFetched, intRecordsToBeDisplayed,
				intCountTotal, intBlockLength, intLastPage, intPageID,
				isNext);
		strPagingLinks = wap.rockvilletech.util.Paging.getPagingLinks();
                }
    }// end if vector 
%>
<div>
<table cellpadding="0" cellspacing="0" width="100%">
      <tr><td align="left" style="padding:5px 0px 0px 10px;">
            <table bgcolor="#d5d5d5" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td><img src="<%=request.getContextPath()%>/images/bar_left.png" alt="" /></td>
                    <td><b>&nbsp;Fun Search&nbsp;</b></td>
                    <td><img src="<%=request.getContextPath()%>/images/bar_right.png" alt="" /></td>
                </tr>
            </table>
      </td></tr>
<tr><td align="left" style="background-image:url('images/new/catagory_top_part.jpg');background-repeat: repeat-x; padding:6px 0px 0px 0px; ">

<%
       try {
	       String ititle ="";
	       String str_stuff_id = "";
	       String str_fun_item_id="";
	       String[] arrNews=null;
               //SeqID,Category,ContentData,ContentData_UR
            if(vFun.size()==2){
                strPagingLinks="No Data Available!";
            }   
           for (int idx = 2; idx < vFun.size(); idx++) {
               arrNews =(String[]) vFun.get(idx);
               str_stuff_id = arrNews[1];
               str_stuff_id = map_coolstuff_cat(str_stuff_id);
               ititle = arrNews[2];
                str_fun_item_id=arrNews[0];
                ititle = wap.rockvilletech.util.StringUtils.toUnicode(ititle);
                try{
                ititle=java.net.URLDecoder.decode(ititle,"UTF-8");
                }catch(Exception exDecode){
                }
                if(ititle.length()>30){
                ititle = ititle.substring(0,30);
                }else if(ititle.length()>15 && ititle.length()<20){
                    ititle = ititle.substring(0,16);
                }
%>
		<div>&nbsp; - <a class="LinkIndex" href="<%=request.getContextPath()%>/coolstuff/price_2.jsp?txtsrh=<%=strSearchText%>&stuff=<%=str_stuff_id%>&item=<%=str_fun_item_id%>">
                        <%=ititle+" ..."%></a></div>
<%
          }
		
		out.println(strPagingLinks);


       } catch (Exception exRssNewsSearch) {
       }
%>
    </td>
    </tr>
                </table>
           </div>
       <br/>

<%-- End --%>